﻿namespace YidanSoft.Library.EditorUtility.WinControls
{
    using System;
    using System.Diagnostics;
    using System.Drawing;
    using System.Threading;
    using System.Windows.Forms;
    using YidanSoft.Library.EditorUtility.General;
    using YidanSoft.Library.EditorUtility.Win32;

    public class ProgressBarEx : Control
    {
        private int _value;
        private Bitmap backgroundBitmap;
        private Color backgroundColor;
        private ProgressBarType barType;
        private Border3DStyle border3D;
        private Color borderColor;
        private bool enableBorder3D;
        private Bitmap foregroundBitmap;
        private Color foregroundColor;
        private Color gradientEndColor;
        private Color gradientMiddleColor;
        private Color gradientStartColor;
        private int max;
        private int min;
        private Color progressTextColor;
        private Color progressTextHiglightColor;
        private ProgressBarPropertyChangedHandler PropertyChanged;
        private bool showProgressText;
        private bool smooth;
        private int step;

        public event ProgressBarPropertyChangedHandler PropertyChanged
        {
            add
            {
                ProgressBarPropertyChangedHandler handler2;
                ProgressBarPropertyChangedHandler propertyChanged = this.PropertyChanged;
                do
                {
                    handler2 = propertyChanged;
                    ProgressBarPropertyChangedHandler handler3 = (ProgressBarPropertyChangedHandler) Delegate.Combine(handler2, value);
                    propertyChanged = Interlocked.CompareExchange<ProgressBarPropertyChangedHandler>(ref this.PropertyChanged, handler3, handler2);
                }
                while (propertyChanged != handler2);
            }
            remove
            {
                ProgressBarPropertyChangedHandler handler2;
                ProgressBarPropertyChangedHandler propertyChanged = this.PropertyChanged;
                do
                {
                    handler2 = propertyChanged;
                    ProgressBarPropertyChangedHandler handler3 = (ProgressBarPropertyChangedHandler) Delegate.Remove(handler2, value);
                    propertyChanged = Interlocked.CompareExchange<ProgressBarPropertyChangedHandler>(ref this.PropertyChanged, handler3, handler2);
                }
                while (propertyChanged != handler2);
            }
        }

        public ProgressBarEx()
        {
            this._value = 0;
            this.step = 1;
            this.min = 0;
            this.max = 100;
            this.smooth = false;
            this.border3D = Border3DStyle.Flat;
            this.enableBorder3D = false;
            this.showProgressText = false;
            this.progressTextHiglightColor = Color.Empty;
            this.progressTextColor = Color.Empty;
            this.barType = ProgressBarType.Standard;
            this.foregroundBitmap = null;
            this.backgroundBitmap = null;
            this.gradientStartColor = Color.Empty;
            this.gradientMiddleColor = Color.Empty;
            this.gradientEndColor = Color.Empty;
            this.InitializeProgressControl(ProgressBarType.Standard, ColorUtil.VSNetControlColor, ColorUtil.VSNetBorderColor, SystemColors.Highlight, null, null, Color.Empty, Color.Empty, Color.Empty);
        }

        public ProgressBarEx(Bitmap foregroundBitmap)
        {
            this._value = 0;
            this.step = 1;
            this.min = 0;
            this.max = 100;
            this.smooth = false;
            this.border3D = Border3DStyle.Flat;
            this.enableBorder3D = false;
            this.showProgressText = false;
            this.progressTextHiglightColor = Color.Empty;
            this.progressTextColor = Color.Empty;
            this.barType = ProgressBarType.Standard;
            this.foregroundBitmap = null;
            this.backgroundBitmap = null;
            this.gradientStartColor = Color.Empty;
            this.gradientMiddleColor = Color.Empty;
            this.gradientEndColor = Color.Empty;
            this.InitializeProgressControl(ProgressBarType.Bitmap, ColorUtil.VSNetControlColor, ColorUtil.VSNetBorderColor, ColorUtil.VSNetBorderColor, foregroundBitmap, null, Color.Empty, Color.Empty, Color.Empty);
        }

        public ProgressBarEx(Bitmap foregroundBitmap, Bitmap backgroundBitmap)
        {
            this._value = 0;
            this.step = 1;
            this.min = 0;
            this.max = 100;
            this.smooth = false;
            this.border3D = Border3DStyle.Flat;
            this.enableBorder3D = false;
            this.showProgressText = false;
            this.progressTextHiglightColor = Color.Empty;
            this.progressTextColor = Color.Empty;
            this.barType = ProgressBarType.Standard;
            this.foregroundBitmap = null;
            this.backgroundBitmap = null;
            this.gradientStartColor = Color.Empty;
            this.gradientMiddleColor = Color.Empty;
            this.gradientEndColor = Color.Empty;
            this.InitializeProgressControl(ProgressBarType.Bitmap, ColorUtil.VSNetControlColor, ColorUtil.VSNetBorderColor, ColorUtil.VSNetBorderColor, foregroundBitmap, backgroundBitmap, Color.Empty, Color.Empty, Color.Empty);
        }

        public ProgressBarEx(Color gradientStartColor, Color gradientEndColor)
        {
            this._value = 0;
            this.step = 1;
            this.min = 0;
            this.max = 100;
            this.smooth = false;
            this.border3D = Border3DStyle.Flat;
            this.enableBorder3D = false;
            this.showProgressText = false;
            this.progressTextHiglightColor = Color.Empty;
            this.progressTextColor = Color.Empty;
            this.barType = ProgressBarType.Standard;
            this.foregroundBitmap = null;
            this.backgroundBitmap = null;
            this.gradientStartColor = Color.Empty;
            this.gradientMiddleColor = Color.Empty;
            this.gradientEndColor = Color.Empty;
            this.InitializeProgressControl(ProgressBarType.Gradient, ColorUtil.VSNetControlColor, ColorUtil.VSNetBorderColor, ColorUtil.VSNetBorderColor, this.foregroundBitmap, null, gradientStartColor, Color.Empty, gradientEndColor);
        }

        public ProgressBarEx(Color gradientStartColor, Color gradientMiddleColor, Color gradientEndColor)
        {
            this._value = 0;
            this.step = 1;
            this.min = 0;
            this.max = 100;
            this.smooth = false;
            this.border3D = Border3DStyle.Flat;
            this.enableBorder3D = false;
            this.showProgressText = false;
            this.progressTextHiglightColor = Color.Empty;
            this.progressTextColor = Color.Empty;
            this.barType = ProgressBarType.Standard;
            this.foregroundBitmap = null;
            this.backgroundBitmap = null;
            this.gradientStartColor = Color.Empty;
            this.gradientMiddleColor = Color.Empty;
            this.gradientEndColor = Color.Empty;
            this.InitializeProgressControl(ProgressBarType.Gradient, ColorUtil.VSNetControlColor, ColorUtil.VSNetBorderColor, ColorUtil.VSNetBorderColor, this.foregroundBitmap, null, gradientStartColor, gradientMiddleColor, gradientEndColor);
        }

        private void DrawBackground(Graphics g, Rectangle windowRect)
        {
            if (this.barType == ProgressBarType.Standard)
            {
                this.DrawStandardBackground(g, windowRect);
            }
            else if (this.barType == ProgressBarType.Bitmap)
            {
                this.DrawBitmapBackground(g, windowRect);
            }
            else if (this.barType == ProgressBarType.Gradient)
            {
                this.DrawGradientBackground(g, windowRect);
            }
        }

        private void DrawBitmapBackground(Graphics g, Rectangle windowRect)
        {
            if (this.backgroundBitmap != null)
            {
                int width = ((windowRect.Height - 4) * 3) / 4;
                width -= 2;
                Rectangle rectangle = new Rectangle(windowRect.Left + 1, windowRect.Top + 1, width, windowRect.Height - 2);
                for (int i = 0; i < (windowRect.Width - 2); i += width)
                {
                    g.DrawImage(this.backgroundBitmap, rectangle.Left + i, rectangle.Top, width, windowRect.Height);
                    if ((i + width) > (windowRect.Width - 2))
                    {
                        g.DrawImage(this.backgroundBitmap, (rectangle.Left + i) + width, rectangle.Top, (windowRect.Width - 2) - ((rectangle.Left + i) + width), windowRect.Height);
                    }
                }
            }
            else
            {
                windowRect.Inflate(-1, -1);
                g.FillRectangle(new SolidBrush(this.backgroundColor), windowRect);
            }
        }

        private void DrawBitmapForeground(Graphics g, Rectangle windowRect)
        {
            Debug.Assert(this.foregroundBitmap != null);
            int width = ((windowRect.Height - 4) * 3) / 4;
            width -= 2;
            Rectangle rectangle = new Rectangle(2, windowRect.Top + 2, width, windowRect.Height - 4);
            int num2 = this.GetScaledValue() - 2;
            if (num2 < 0)
            {
                num2 = 0;
            }
            int num3 = 2;
            if (this.smooth)
            {
                num3 = 0;
            }
            for (int i = 0; i < num2; i += rectangle.Width + num3)
            {
                if ((((i + rectangle.Width) + num3) > num2) && (((i + rectangle.Width) + num3) > ((windowRect.Width - 2) - num3)))
                {
                    int num5 = (num2 - i) - 2;
                    Rectangle rectangle2 = new Rectangle(rectangle.Left + i, rectangle.Top, num5, rectangle.Height);
                    g.DrawImage(this.foregroundBitmap, rectangle2, 0, 0, rectangle2.Width, rectangle2.Height, GraphicsUnit.Pixel);
                    break;
                }
                Rectangle destRect = new Rectangle(rectangle.Left + i, rectangle.Top, rectangle.Width, rectangle.Height);
                g.DrawImage(this.foregroundBitmap, destRect, 0, 0, destRect.Width, destRect.Height, GraphicsUnit.Pixel);
            }
        }

        private void DrawBorder(Graphics g, Rectangle windowRect)
        {
            if (!this.enableBorder3D)
            {
                g.DrawRectangle(new Pen(this.borderColor), windowRect.Left, windowRect.Top, windowRect.Width - 1, windowRect.Height - 1);
            }
            else
            {
                ControlPaint.DrawBorder3D(g, windowRect, this.border3D);
            }
        }

        private void DrawForeground(Graphics g, Rectangle windowRect)
        {
            if (this.barType == ProgressBarType.Standard)
            {
                this.DrawStandardForeground(g, windowRect);
            }
            else if (this.barType == ProgressBarType.Bitmap)
            {
                this.DrawBitmapForeground(g, windowRect);
            }
            else if (this.barType == ProgressBarType.Gradient)
            {
                this.DrawGradientForeground(g, windowRect);
            }
        }

        private void DrawGradientBackground(Graphics g, Rectangle windowRect)
        {
            windowRect.Inflate(-1, -1);
            g.FillRectangle(new SolidBrush(this.backgroundColor), windowRect);
        }

        private void DrawGradientForeground(Graphics g, Rectangle windowRect)
        {
            bool flag = false;
            if (this.gradientMiddleColor != Color.Empty)
            {
                flag = true;
            }
            if (flag)
            {
                this.DrawThreeColorsGradient(g, windowRect);
            }
            else
            {
                this.DrawTwoColorsGradient(g, windowRect);
            }
        }

        private void DrawStandardBackground(Graphics g, Rectangle windowRect)
        {
            windowRect.Inflate(-1, -1);
            g.FillRectangle(new SolidBrush(this.backgroundColor), windowRect);
        }

        private void DrawStandardForeground(Graphics g, Rectangle windowRect)
        {
            if (this.smooth)
            {
                this.DrawStandardForegroundSmooth(g, windowRect);
            }
            else
            {
                this.DrawStandardForegroundSegmented(g, windowRect);
            }
        }

        private void DrawStandardForegroundSegmented(Graphics g, Rectangle windowRect)
        {
            int width = ((windowRect.Height - 4) * 3) / 4;
            width -= 2;
            Rectangle rectangle = new Rectangle(2, windowRect.Top + 2, width, windowRect.Height - 4);
            int num2 = this.GetScaledValue() - 2;
            if (num2 < 0)
            {
                num2 = 0;
            }
            for (int i = 0; i < num2; i += rectangle.Width + 2)
            {
                if ((((i + rectangle.Width) + 2) > num2) && (((i + rectangle.Width) + 2) > (windowRect.Width - 4)))
                {
                    int num4 = (num2 - i) - 2;
                    g.FillRectangle(new SolidBrush(this.foregroundColor), rectangle.Left + i, rectangle.Top, num4, rectangle.Height);
                    break;
                }
                g.FillRectangle(new SolidBrush(this.foregroundColor), rectangle.Left + i, rectangle.Top, rectangle.Width, rectangle.Height);
            }
        }

        private void DrawStandardForegroundSmooth(Graphics g, Rectangle windowRect)
        {
            int width = this.GetScaledValue() - 4;
            g.FillRectangle(new SolidBrush(this.foregroundColor), windowRect.Left + 2, windowRect.Top + 2, width, windowRect.Height - 4);
            if (this.ShowProgressText)
            {
                string text = (((this.GetScaledValue() * 100) / windowRect.Width)).ToString() + " %";
                System.Drawing.Size size = TextUtil.GetTextSize(g, text, this.Font);
                Rectangle rect = new Rectangle(windowRect.Left + 2, windowRect.Top + 2, width, windowRect.Height - 4);
                Point point = new Point((windowRect.Width - size.Width) / 2, (windowRect.Height - size.Height) / 2);
                g.Clip = new Region(rect);
                Color progressTextHiglightColor = this.progressTextHiglightColor;
                if (progressTextHiglightColor == Color.Empty)
                {
                    progressTextHiglightColor = SystemColors.HighlightText;
                }
                g.DrawString(text, this.Font, new SolidBrush(progressTextHiglightColor), (PointF) point);
                rect = new Rectangle(width + 2, windowRect.Top + 2, windowRect.Width, windowRect.Height - 4);
                g.Clip = new Region(rect);
                progressTextHiglightColor = this.progressTextColor;
                if (progressTextHiglightColor == Color.Empty)
                {
                    progressTextHiglightColor = SystemColors.ControlText;
                }
                g.DrawString(text, this.Font, new SolidBrush(progressTextHiglightColor), (PointF) point);
            }
        }

        private void DrawThreeColorsGradient(Graphics g, Rectangle windowRect)
        {
            int num7;
            int num8;
            int num9;
            int num10;
            int num11;
            int num12;
            int num = Math.Max(this.gradientStartColor.R, this.gradientMiddleColor.R) - Math.Min(this.gradientStartColor.R, this.gradientMiddleColor.R);
            int num2 = Math.Max(this.gradientStartColor.G, this.gradientMiddleColor.G) - Math.Min(this.gradientStartColor.G, this.gradientMiddleColor.G);
            int num3 = Math.Max(this.gradientStartColor.B, this.gradientMiddleColor.B) - Math.Min(this.gradientStartColor.B, this.gradientMiddleColor.B);
            int num4 = Math.Max(this.gradientEndColor.R, this.gradientMiddleColor.R) - Math.Min(this.gradientEndColor.R, this.gradientMiddleColor.R);
            int num5 = Math.Max(this.gradientEndColor.G, this.gradientMiddleColor.G) - Math.Min(this.gradientEndColor.G, this.gradientMiddleColor.G);
            int num6 = Math.Max(this.gradientEndColor.B, this.gradientMiddleColor.B) - Math.Min(this.gradientEndColor.B, this.gradientMiddleColor.B);
            if (this.gradientStartColor.R < this.gradientMiddleColor.R)
            {
                num7 = 1;
            }
            else
            {
                num7 = -1;
            }
            if (this.gradientStartColor.G < this.gradientMiddleColor.G)
            {
                num8 = 1;
            }
            else
            {
                num8 = -1;
            }
            if (this.gradientStartColor.B < this.gradientMiddleColor.B)
            {
                num9 = 1;
            }
            else
            {
                num9 = -1;
            }
            if (this.gradientMiddleColor.R < this.gradientEndColor.R)
            {
                num10 = 1;
            }
            else
            {
                num10 = -1;
            }
            if (this.gradientMiddleColor.G < this.gradientEndColor.G)
            {
                num11 = 1;
            }
            else
            {
                num11 = -1;
            }
            if (this.gradientMiddleColor.B < this.gradientEndColor.B)
            {
                num12 = 1;
            }
            else
            {
                num12 = -1;
            }
            int width = ((windowRect.Height - 4) * 3) / 4;
            width -= 2;
            int num14 = 2;
            if (this.smooth)
            {
                num14 = 0;
            }
            int num15 = (windowRect.Width - 4) / (width + num14);
            num /= num15 / 2;
            num2 /= num15 / 2;
            num3 /= num15 / 2;
            num4 /= num15 / 2;
            num5 /= num15 / 2;
            num6 /= num15 / 2;
            Rectangle rectangle = new Rectangle(2, windowRect.Top + 2, width, windowRect.Height - 4);
            int num16 = this.GetScaledValue() - 2;
            if (num16 < 0)
            {
                num16 = 0;
            }
            int num17 = 0;
            bool flag = true;
            for (int i = 0; i < num16; i += rectangle.Width + num14)
            {
                Color empty = Color.Empty;
                if (i < ((windowRect.Width - 4) / 2))
                {
                    empty = Color.FromArgb(this.gradientStartColor.R + ((num * num17) * num7), this.gradientStartColor.G + ((num2 * num17) * num8), this.gradientStartColor.B + ((num3 * num17) * num9));
                }
                else
                {
                    if (flag)
                    {
                        flag = false;
                        num17 = 0;
                    }
                    empty = Color.FromArgb(this.gradientMiddleColor.R + ((num4 * num17) * num10), this.gradientMiddleColor.G + ((num5 * num17) * num11), this.gradientMiddleColor.B + ((num6 * num17) * num12));
                }
                if ((((i + rectangle.Width) + num14) > num16) && (((i + rectangle.Width) + num14) > ((windowRect.Width - 2) - num14)))
                {
                    int num19 = (num16 - i) - 2;
                    Rectangle rectangle2 = new Rectangle(rectangle.Left + i, rectangle.Top, num19, rectangle.Height);
                    g.FillRectangle(new SolidBrush(empty), rectangle2);
                    break;
                }
                Rectangle rect = new Rectangle(rectangle.Left + i, rectangle.Top, rectangle.Width, rectangle.Height);
                g.FillRectangle(new SolidBrush(empty), rect);
                num17++;
            }
        }

        private void DrawTwoColorsGradient(Graphics g, Rectangle windowRect)
        {
            int num4;
            int num5;
            int num6;
            int num = Math.Max(this.gradientEndColor.R, this.gradientStartColor.R) - Math.Min(this.gradientEndColor.R, this.gradientStartColor.R);
            int num2 = Math.Max(this.gradientEndColor.G, this.gradientStartColor.G) - Math.Min(this.gradientEndColor.G, this.gradientStartColor.G);
            int num3 = Math.Max(this.gradientEndColor.B, this.gradientStartColor.B) - Math.Min(this.gradientEndColor.B, this.gradientStartColor.B);
            if (this.gradientEndColor.R > this.gradientStartColor.R)
            {
                num4 = 1;
            }
            else
            {
                num4 = -1;
            }
            if (this.gradientEndColor.G > this.gradientStartColor.G)
            {
                num5 = 1;
            }
            else
            {
                num5 = -1;
            }
            if (this.gradientEndColor.B > this.gradientStartColor.B)
            {
                num6 = 1;
            }
            else
            {
                num6 = -1;
            }
            int width = ((windowRect.Height - 4) * 3) / 4;
            width -= 2;
            int num8 = 2;
            if (this.smooth)
            {
                num8 = 0;
            }
            int num9 = (windowRect.Width - 4) / (width + num8);
            num /= num9;
            num2 /= num9;
            num3 /= num9;
            Rectangle rectangle = new Rectangle(2, windowRect.Top + 2, width, windowRect.Height - 4);
            int num10 = this.GetScaledValue() - 2;
            if (num10 < 0)
            {
                num10 = 0;
            }
            int num11 = 0;
            for (int i = 0; i < num10; i += rectangle.Width + num8)
            {
                Color color = Color.FromArgb(this.gradientStartColor.R + ((num * num11) * num4), this.gradientStartColor.G + ((num2 * num11) * num5), this.gradientStartColor.B + ((num3 * num11) * num6));
                if ((((i + rectangle.Width) + num8) > num10) && (((i + rectangle.Width) + num8) > ((windowRect.Width - 2) - num8)))
                {
                    int num13 = (num10 - i) - 2;
                    Rectangle rectangle2 = new Rectangle(rectangle.Left + i, rectangle.Top, num13, rectangle.Height);
                    g.FillRectangle(new SolidBrush(color), rectangle2);
                    break;
                }
                Rectangle rect = new Rectangle(rectangle.Left + i, rectangle.Top, rectangle.Width, rectangle.Height);
                g.FillRectangle(new SolidBrush(color), rect);
                num11++;
            }
        }

        private void FirePropertyChange(ProgressBarProperty property)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, property);
            }
            base.Invalidate();
        }

        private int GetScaledValue()
        {
            int num = this._value;
            System.Drawing.Size size = this.Size;
            return (((this._value - this.min) * size.Width) / (this.max - this.min));
        }

        private void InitializeProgressControl(ProgressBarType barType, Color backgroundColor, Color foregroundColor, Color borderColor, Bitmap foregroundBitmap, Bitmap backgroundBitmap, Color gradientStartColor, Color gradientMiddleColor, Color gradientEndColor)
        {
            base.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
            this.barType = barType;
            this.backgroundColor = backgroundColor;
            this.foregroundColor = foregroundColor;
            this.borderColor = borderColor;
            this.foregroundBitmap = foregroundBitmap;
            this.backgroundBitmap = backgroundBitmap;
            this.gradientStartColor = gradientStartColor;
            this.gradientMiddleColor = gradientMiddleColor;
            this.gradientEndColor = gradientEndColor;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            YidanSoft.Library.EditorUtility.Win32.RECT rect = new YidanSoft.Library.EditorUtility.Win32.RECT();
            WindowsAPI.GetWindowRect(base.Handle, ref rect);
            Rectangle windowRect = new Rectangle(0, 0, rect.right - rect.left, rect.bottom - rect.top);
            Graphics g = e.Graphics;
            this.DrawBackground(g, windowRect);
            this.DrawBorder(g, windowRect);
            this.DrawForeground(g, windowRect);
        }

        public void PerformStep()
        {
            if (this._value < this.max)
            {
                this._value += this.step;
            }
            if (this._value > this.max)
            {
                this._value = this.max;
            }
            this.FirePropertyChange(ProgressBarProperty.Step);
        }

        public Bitmap BackgroundBitmap
        {
            get
            {
                return this.backgroundBitmap;
            }
            set
            {
                if (this.backgroundBitmap != value)
                {
                    this.backgroundBitmap = value;
                    this.FirePropertyChange(ProgressBarProperty.BackgroundBitmap);
                }
            }
        }

        public Color BackgroundColor
        {
            get
            {
                return this.backgroundColor;
            }
            set
            {
                if (this.backgroundColor != value)
                {
                    this.backgroundColor = value;
                    this.FirePropertyChange(ProgressBarProperty.BackgroundColor);
                }
            }
        }

        public Border3DStyle Border3D
        {
            get
            {
                return this.border3D;
            }
            set
            {
                if (this.border3D != value)
                {
                    this.border3D = value;
                    this.FirePropertyChange(ProgressBarProperty.Border3D);
                }
            }
        }

        public Color BorderColor
        {
            get
            {
                return this.borderColor;
            }
            set
            {
                if (this.borderColor != value)
                {
                    this.borderColor = value;
                    this.FirePropertyChange(ProgressBarProperty.BorderColor);
                }
            }
        }

        public bool EnableBorder3D
        {
            get
            {
                return this.enableBorder3D;
            }
            set
            {
                if (this.enableBorder3D != value)
                {
                    this.enableBorder3D = value;
                    this.FirePropertyChange(ProgressBarProperty.Border3D);
                }
            }
        }

        public Bitmap ForegroundBitmap
        {
            get
            {
                return this.foregroundBitmap;
            }
            set
            {
                if (this.foregroundBitmap != value)
                {
                    this.foregroundBitmap = value;
                    this.FirePropertyChange(ProgressBarProperty.ForegroundBitmap);
                }
            }
        }

        public Color ForegroundColor
        {
            get
            {
                return this.foregroundColor;
            }
            set
            {
                if (this.foregroundColor != value)
                {
                    this.foregroundColor = value;
                    this.FirePropertyChange(ProgressBarProperty.ForegroundColor);
                }
            }
        }

        public Color GradientEndColor
        {
            get
            {
                return this.gradientEndColor;
            }
            set
            {
                if (this.gradientEndColor != value)
                {
                    this.gradientEndColor = value;
                    this.FirePropertyChange(ProgressBarProperty.GradientEndColor);
                }
            }
        }

        public Color GradientMiddleColor
        {
            get
            {
                return this.gradientMiddleColor;
            }
            set
            {
                if (this.gradientMiddleColor != value)
                {
                    this.gradientMiddleColor = value;
                    this.FirePropertyChange(ProgressBarProperty.GradientMiddleColor);
                }
            }
        }

        public Color GradientStartColor
        {
            get
            {
                return this.gradientStartColor;
            }
            set
            {
                if (this.gradientStartColor != value)
                {
                    this.gradientStartColor = value;
                    this.FirePropertyChange(ProgressBarProperty.GradientStartColor);
                }
            }
        }

        public int Maximum
        {
            get
            {
                return this.max;
            }
            set
            {
                if (this.max != value)
                {
                    if (value <= this.min)
                    {
                        string message = "ProgressBarEx Maximum Value: " + value.ToString() + " is out of range. It needs to be greater than Minimum value: " + this.min.ToString();
                        ArgumentOutOfRangeException exception = new ArgumentOutOfRangeException("Value", message);
                        throw exception;
                    }
                    this.max = value;
                    this.FirePropertyChange(ProgressBarProperty.Maximun);
                }
            }
        }

        public int Minimum
        {
            get
            {
                return this.min;
            }
            set
            {
                if (this.min != value)
                {
                    if (value >= this.max)
                    {
                        string message = "ProgressBarEx Minimum Value: " + value.ToString() + " is out of range. It needs to be less than Maximun value: " + this.max.ToString();
                        ArgumentOutOfRangeException exception = new ArgumentOutOfRangeException("Value", message);
                        throw exception;
                    }
                    this.min = value;
                    this.FirePropertyChange(ProgressBarProperty.Minimun);
                }
            }
        }

        public Color ProgressTextColor
        {
            get
            {
                return this.progressTextColor;
            }
            set
            {
                if (this.progressTextColor != value)
                {
                    this.progressTextColor = value;
                    this.FirePropertyChange(ProgressBarProperty.ProgressTextColor);
                }
            }
        }

        public Color ProgressTextHiglightColor
        {
            get
            {
                return this.progressTextHiglightColor;
            }
            set
            {
                if (this.progressTextHiglightColor != value)
                {
                    this.progressTextHiglightColor = value;
                    this.FirePropertyChange(ProgressBarProperty.ProgressTextHiglightColor);
                }
            }
        }

        public bool ShowProgressText
        {
            get
            {
                return this.showProgressText;
            }
            set
            {
                if (this.showProgressText != value)
                {
                    this.showProgressText = value;
                    this.FirePropertyChange(ProgressBarProperty.ShowProgressText);
                }
            }
        }

        public System.Drawing.Size Size
        {
            get
            {
                return base.Size;
            }
            set
            {
                System.Drawing.Size size = value;
                if ((size.Width % 2) != 0)
                {
                    size.Width++;
                }
                if ((size.Height % 2) != 0)
                {
                    size.Height++;
                }
                base.Size = size;
            }
        }

        public bool Smooth
        {
            get
            {
                return this.smooth;
            }
            set
            {
                if (this.smooth != value)
                {
                    this.smooth = value;
                    this.FirePropertyChange(ProgressBarProperty.Smooth);
                }
            }
        }

        public int Step
        {
            get
            {
                return this.step;
            }
            set
            {
                if (this.step != value)
                {
                    this.step = value;
                    this.FirePropertyChange(ProgressBarProperty.Step);
                }
            }
        }

        public int Value
        {
            get
            {
                return this._value;
            }
            set
            {
                if (this._value != value)
                {
                    if ((value > this.max) || (value < this.min))
                    {
                        string message = "ProgressBarEx Value: " + value.ToString() + " is out of range. It needs to be between " + this.min.ToString() + " and " + this.max.ToString();
                        ArgumentOutOfRangeException exception = new ArgumentOutOfRangeException("Value", message);
                        throw exception;
                    }
                    this._value = value;
                    this.FirePropertyChange(ProgressBarProperty.Value);
                }
            }
        }

        private enum ProgressBarType
        {
            Standard,
            Bitmap,
            Gradient
        }
    }
}

